﻿using FluentNHibernate.Mapping;

namespace ControleRepresentante.Logic.Models.Maps
{
    public class ClienteMap : SubclassMap<Cliente>
    {
        public ClienteMap()
        {
            Map(x => x.RazaoSocial)
                .Not.Nullable();
            Map(x => x.NomeFantasia)
                .Not.Nullable();
            References(x => x.Vendedor)
                .Nullable()
                .Cascade.None();
            References(x => x.EnderecoEntrega)
                .Nullable();
            References(x => x.EnderecoCobranca)
                .Nullable();
            Map(x => x.CNPJ)
                .Nullable();
            Map(x => x.InscricaoEstadual)
                .Nullable();
            HasMany(x => x.Pedidos)
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.Delete()
                .Inverse();
            HasOne(x => x.ClienteJolitex)
                .Cascade.All();
            Map(x => x.ClienteDesde)
                .Nullable();
            HasMany(x => x.RelatorioVisitas)
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.Delete()
                .Inverse();
        }
    }

    public class ClienteJolitexMap : MapBase<ClienteJolitex>
    {
        public ClienteJolitexMap()
        {
            Map(x => x.Codigo)
                .Nullable();
            Map(x => x.Regiao)
                .Nullable();
            HasOne(x => x.Cliente);
        }
    }
}
